package com.zscat.mallplus.oms.entity;

import cn.afterturn.easypoi.excel.annotation.Excel;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.zscat.mallplus.sys.entity.SysShop;
import com.zscat.mallplus.utils.BaseEntity;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.springframework.format.annotation.DateTimeFormat;

import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

/**
 * <p>
 * 订单表
 * </p>
 *
 * @author zscat
 * @since 2019-04-17
 */
@Data
@ApiModel(value ="订单详情",description = "订单详情信息")
@TableName("oms_order")
public class OmsOrder extends BaseEntity implements Serializable {

    private static final long serialVersionUID = 1L;

    @TableField(exist = false)
    private List<OmsOrder> childList;
    @TableField(exist = false)
    private BigDecimal blance;
    @TableField(exist = false)
    private Long afterbillId;
    @TableField(exist = false)
    private SysShop shop;
    @TableField(exist = false)
    private List<OmsOrderItem> orderItemList;
    @TableField(exist = false)
    private List<OmsOrderOperateHistory> historyList;

    /**
     * 订单id
     */
    @Excel(name = "编号")
    @ApiModelProperty(name = "订单ID",notes = "id")
    @TableId(value = "id", type = IdType.AUTO)
    private Long id;

    private Long pid;

    @ApiModelProperty(value ="用户ID",name = "memberId")
    @TableField("member_id")
    private Long memberId;
    @ApiModelProperty(value ="优惠券ID",name = "memberId")
    @TableField("coupon_id")
    private Long couponId;

    /**
     * 订单编号
     */
    @Excel(name = "订单号")
    @ApiModelProperty(value ="订单号",name = "orderSn")
    @TableField("order_sn")
    private String orderSn;

    /**
     * 提交时间
     */
    @ApiModelProperty(value ="提交时间",name = "createTime")
    @TableField("create_time")
    private Date createTime;

    /**
     * 用户账号
     */
    @Excel(name = "用户账号")
    @ApiModelProperty(value ="用户账号",name = "memberUsername")
    @TableField("member_username")
    private String memberUsername;

    @TableField(exist = false)
    private Integer totalCount;

    /**
     * 订单总金额
     */
    @Excel(name = "订单金额")
    @ApiModelProperty(value ="订单总金额",name = "totalAmount")
    @TableField("total_amount")
    private BigDecimal totalAmount;

    /**
     * 应付金额（实际支付金额）
     */
    @Excel(name = "支付金额")
    @ApiModelProperty(value ="应付金额（实际支付金额）",name = "payAmount")
    @TableField("pay_amount")
    private BigDecimal payAmount;

    /**
     * 运费金额
     */
    @ApiModelProperty(value ="运费金额",name = "freightAmount")
    @TableField("freight_amount")
    private BigDecimal freightAmount;

    /**
     * 促销优化金额（促销价、满减、阶梯价）
     */
    @ApiModelProperty(value ="促销优化金额（促销价、满减、阶梯价）",name = "promotionAmount")
    @TableField("promotion_amount")
    private BigDecimal promotionAmount;

    /**
     * 积分抵扣金额
     */
    @ApiModelProperty(value ="积分抵扣金额",name = "integrationAmount")
    @TableField("integration_amount")
    private BigDecimal integrationAmount;
    /**
     * 会员折扣金额
     */
    @ApiModelProperty(value ="会员折扣金额",name = "vipAmount")
    @TableField("vip_amount")
    private BigDecimal vipAmount;

    /**
     * 优惠券抵扣金额
     */
    @ApiModelProperty(value ="优惠券抵扣金额",name = "couponAmount")
    @TableField("coupon_amount")
    private BigDecimal couponAmount;

    /**
     * 管理员后台调整订单使用的折扣金额
     */
    @ApiModelProperty(value ="管理员后台调整订单使用的折扣金额",name = "discountAmount")
    @TableField("discount_amount")
    private BigDecimal discountAmount;

    /**
     * 支付方式：0->未支付；1->支付宝；2->微信；3->余额支付；4->积分兑换
     */
    @ApiModelProperty(value ="支付方式：0->未支付；1->支付宝；2->微信；3->余额支付；4->积分兑换",name = "payType")
    @TableField("pay_type")
    private Integer payType;

    /**
     * 订单来源：1->小程序；2->H5；3->PC；4->APP
     */
    @ApiModelProperty(value ="订单来源：1->小程序；2->H5；3->PC；4->APP", name = "sourceType")
    @TableField("source_type")
    private Integer sourceType;

    /**
     * 订单状态：0->待付款；1->待发货；2->已发货待收货；3->已完成；4->已关闭；5->可使用
     */
    @ApiModelProperty(value ="订单状态：0->待付款；1->待发货；2->已发货待收货；3->已完成；4->已关闭；5->可使用", name = "status")
    @TableField("status")
    private Integer status;

    /**
     * 订单类型：1->正常订单；2->秒杀订单；3->拼团订单；4->积分订单
     */
    @ApiModelProperty(value = "订单类型",name = "orderType",notes ="订单类型：1->正常订单；2->秒杀订单；3->拼团订单；4->积分订单" )
    @TableField("order_type")
    private Integer orderType;

    /**
     * 物流公司(配送方式)
     */
    @ApiModelProperty(value = "物流公司(配送方式)",name = "deliveryCompany",notes ="物流公司(配送方式)" )
    @TableField("delivery_company")
    private String deliveryCompany;

    /**
     * 物流单号
     */
    @ApiModelProperty(value = "物流单号",name = "deliverySn",notes ="物流公司(配送方式)" )
    @TableField("delivery_sn")
    private String deliverySn;

    /**
     * 自动确认时间（天）
     */
    @ApiModelProperty(value = "自动确认时间（天）",name = "autoConfirmDay",notes ="自动确认时间（天）" )
    @TableField("auto_confirm_day")
    private Integer autoConfirmDay;

    /**
     * 下单送积分
     */
    @ApiModelProperty(value = "下单送积分",name = "integration",notes ="下单送积分" )
    private Integer integration;

    /**
     * 门店编号
     */
    @ApiModelProperty(value = "门店编号",name = "growth",notes ="门店编号" )
    private Integer growth;

    /**
     * 活动信息
     */
    @ApiModelProperty(value = "活动信息",name = "promotionInfo",notes ="活动信息" )
    @TableField("promotion_info")
    private String promotionInfo;

    /**
     * 发票类型：0->不开发票；1->电子发票；2->纸质发票
     */
    @ApiModelProperty(value = "发票类型",name = "billType",notes ="发票类型：0->不开发票；1->电子发票；2->纸质发票" )
    @TableField("bill_type")
    private Integer billType;

    /**
     * 发票抬头
     */
    @ApiModelProperty(value = "发票抬头",name = "billHeader",notes ="发票抬头" )
    @TableField("bill_header")
    private String billHeader;

    /**
     * 发票内容
     */
    @ApiModelProperty(value = "发票内容",name = "billContent",notes ="发票内容" )
    @TableField("bill_content")
    private String billContent;

    /**
     * 收票人电话
     */
    @ApiModelProperty(value = "收票人电话",name = "billReceiverPhone",notes ="收票人电话" )
    @TableField("bill_receiver_phone")
    private String billReceiverPhone;

    /**
     * 收票人邮箱
     */
    @ApiModelProperty(value = "收票人邮箱",name = "billReceiverEmail",notes ="收票人邮箱" )
    @TableField("bill_receiver_email")
    private String billReceiverEmail;

    /**
     * 收货人姓名
     */
    @ApiModelProperty(value = "收货人姓名",name = "receiverName",notes ="收货人姓名" )
    @TableField("receiver_name")
    private String receiverName;

    /**
     * 收货人电话
     */
    @ApiModelProperty(value = "收货人电话",name = "receiverPhone",notes ="收货人电话" )
    @TableField("receiver_phone")
    private String receiverPhone;

    @ApiModelProperty(value = "收货人编号",name = "receiverId",notes ="收货人编号" )
    @TableField("receiver_id")
    private Long receiverId;


    /**
     * 收货人邮编
     */
    @ApiModelProperty(value = "收货人邮编",name = "receiverPostCode",notes ="收货人邮编" )
    @TableField("receiver_post_code")
    private String receiverPostCode;

    /**
     * 省份/直辖市
     */
    @TableField("receiver_province")
    private String receiverProvince;

    /**
     * 城市
     */
    @TableField("receiver_city")
    private String receiverCity;

    /**
     * 区
     */
    @TableField("receiver_region")
    private String receiverRegion;

    /**
     * 详细地址
     */
    @TableField("receiver_detail_address")
    private String receiverDetailAddress;

    /**
     * 订单备注
     */
    private String note;

    /**
     * 确认收货状态：0->未确认；1->已确认
     */
    @TableField("confirm_status")
    private Integer confirmStatus;

    /**
     * 删除状态：0->未删除；1->已删除
     */
    @TableField("delete_status")
    private Integer deleteStatus;

    /**
     * 下单时使用的积分
     */
    @TableField("use_integration")
    private Integer useIntegration;

    /**
     * 支付时间
     */
    @Excel(name = "支付时间")
    @TableField("payment_time")
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private Date paymentTime;

    /**
     * 发货时间
     */
    @TableField("delivery_time")
    private Date deliveryTime;

    /**
     * 确认收货时间
     */
    @TableField("receive_time")
    private Date receiveTime;

    /**
     * 评价时间
     */
    @TableField("comment_time")
    private Date commentTime;

    /**
     * 修改时间
     */
    @TableField("modify_time")
    private Date modifyTime;

    @TableField("prepay_id")
    private String prepayId;

    @TableField("supply_id")
    private Long supplyId;

    @TableField("goods_id")
    private Long goodsId;

    @Excel(name = "商品名称")
    @TableField("goods_name")
    private String goodsName;

    @TableField("school_id")
    private Long schoolId;
    @TableField("group_id")
    private Long groupId;
    /**
     * 开票状态：-1->待开票；0->开票中；1->已开票
     */
    @TableField("is_tax")
    private Integer isTax;
    @TableField("tax_type")
    private Integer taxType;    //	是否开发票 1=不发票 2=个人发票 3=公司发票
    @TableField("tax_content")
    private String taxContent;    //	0	发票内容
    @TableField("tax_code")
    private String taxCode;    //	税号
    @TableField("tax_title")
    private String taxTitle;    //	发票抬头

    /**
     * 发票申请时间
     */
    @TableField("tax_apply_time")
    private Date taxApplyTime;

    /**
     * 发票上传时间
     */
    @TableField("tax_apply_time")
    private Date taxUploadTime;
    @TableField("is_comment")
    private Integer isComment;    //是否评论，1未评论，2已评论

    @Excel(name = "科技馆")
    @TableField("store_name")
    private String storeName;    //	科技馆名称

    @Excel(name = "支付方式")
    @TableField(exist = false)
    private String payTypeName;

    @Excel(name = "订单类型")
    @TableField(exist = false)
    private String orderTypeName;  // 订单类型名称

    @Excel(name = "订单状态")
    @TableField(exist = false)
    private String statusName;

    @TableField("after_sale_status")
    private Integer afterSaleStatus; // 售后状态：0->禁止；1->允许

    public String getPayTypeName() {
        if (this.payType == 0) {
            return "未支付";
        } else if (this.payType == 1) {
            return "支付宝支付";
        } else if (this.payType == 2) {
            return "微信支付";
        } else if (this.payType == 3) {
            return "余额支付";
        } else {
            return "积分支付";
        }
    }

    public String getOrderTypeName() {
        if (this.orderType == 1) {
            return "普通订单";
        } else if (this.orderType == 2) {
            return "秒杀订单";
        } else if (this.orderType == 3) {
            return "拼团订单";
        } else {
            return "积分订单";
        }
    }

    public String getStatusName() {
        if (this.status == 0) {
            return "待付款";
        } else if (this.status == 1) {
            return "待发货";
        } else if (this.status == 2) {
            return "待收货";
        } else if (this.status == 3) {
            return "已完成";
        } else if (this.status == 4) {
            return "已关闭";
        } else {
            return "待核销";
        }
    }
}
